package com.cwj.lab3;

import com.cwj.lab1.myArrayList;

public class DFS {
    /**
     * 深度优先搜索
     * */
    public myArrayList<Integer> DFSString(Graph_matrix graph,int start){
        boolean[]vis=new boolean[graph.getV_num()];
        myArrayList<Integer>dfsList=new myArrayList<>();
        DFSString(graph,start,vis,dfsList);
        return  dfsList;
    }
    private void DFSString(Graph_matrix graph,int ind,boolean[]vis,myArrayList<Integer>dfsList){
        if(vis[ind]==true){
            return ;
        }
        vis[ind]=true;
        dfsList.addLast(ind);
        for (int i = 0; i < graph.getV_num(); i++) {
            if(i==ind){
                continue;
            }
            if(graph.getVal(ind,i)== graph.getINF()){
                continue;
            }
            DFSString(graph,i,vis,dfsList);
        }
    }
}
